package com.tianji.learning.controller;

import com.tianji.common.domain.dto.PageDTO;
import com.tianji.learning.domain.dto.QuestionFormDTO;
import com.tianji.learning.domain.query.QuestionPageQuery;
import com.tianji.learning.domain.vo.QuestionVO;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import com.tianji.learning.service.IInteractionQuestionService;
import com.tianji.learning.domain.po.InteractionQuestion;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * <p>
 * 互动提问的问题表 控制器
 * </p>
 *
 * @author zpf
 */
@Api(tags = "问题管理")
@RestController
@RequiredArgsConstructor
@RequestMapping("/questions")
public class InteractionQuestionController {

    private final IInteractionQuestionService interactionQuestionService;
    /**
     * 新增提问
     */
    @PostMapping
    @ApiOperation("新增提问")
    public void addQuestion(@Valid @RequestBody QuestionFormDTO dto){
        interactionQuestionService.addQuestion(dto);
    }

    /**
     * 修改提问
     */
    @ApiOperation("修改提问")
    @PutMapping("/{id}")
    public void updateQuestion(
            @ApiParam("要修改的问题的id") @PathVariable("id") Long id,
            @RequestBody QuestionFormDTO questionDTO){
        interactionQuestionService.updateQuestion(id, questionDTO);
    }
    /**
     * 分页查询问题
     */
    @ApiOperation("分页查询问题")
    @GetMapping("/page")
    public PageDTO<QuestionVO> pageQuery(QuestionPageQuery query){
        return interactionQuestionService.pageQuery(query);
    }

    @ApiOperation("根据id查询问题")
    @GetMapping("/{id}")
    public QuestionVO queryQuestionById(@PathVariable("id") Long id){
        return interactionQuestionService.queryQuestionById(id);
    }
    @ApiOperation("根据id删除当前用户问题")
    @DeleteMapping("/{id}")
    public void deleteQuestion(@PathVariable("id") Long id){
        interactionQuestionService.deleteById(id);
    }

}
